<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
        content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="true">
<title>Sample</title>
</head>
<body>
<script>
function getPositionSuccess(position){
   var lat = position.coords.latitude;
   var lon = position.coords.longitude;
   alert("你所在的位置： 经度" + lat + "，纬度" + lon);
}
function getPositionError(error){
   switch(error.code){
      case error.TIMEOUT :
         alert("连接超时，请重试");
         break;
      case error.PERMISSION_DENIED :
         alert("你拒绝了使用位置共享服务");
         break;
      case error.POSITION_UNAVAILABLE : 
         alert("无法提供位置服务");
         break;
   }
}

var geolocation = window.navigator.geolocation;
geolocation.getCurrentPosition(getPositionSuccess,
                                     getPositionError);

</script>
</body>
</html>